const { defineConfig } = require('@vue/cli-service')
const fs = require('fs')
const path = require('path')
module.exports = defineConfig({
  transpileDependencies: true,
  chainWebpack: config => {
    config.plugin('define').tap(args => {
      args[0]['AMap'] = 'window.AMap';
      return args;
    });
  },
  
  devServer: {
    
    port: 8082,
    https: {
      key: fs.readFileSync(path.join(__dirname, './cert/key.pem')),
      cert: fs.readFileSync(path.join(__dirname, './cert/cert.pem')),
    },
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        ws: true
      }
    },
    onBeforeSetupMiddleware: function (devServer) {
      devServer.app.use((req, res, next) => {
        if (!req.secure) {
          return res.redirect('https://' + req.headers.host + req.url)
        }
        next()
      })
    }
  }
})
